﻿using MeetAI.Model;
using MeetAI.Model.DTO;
using MeetAI.Service.IService;
using MeetAI.Utility;
using Nancy;
using Nancy.ModelBinding;
using Newtonsoft.Json;
using System;

namespace MeetAI.API.Modules
{
    public class messageTypeModule : NancyModule
    {
        private readonly IDy_Message_Service _dy_Message_Service;
        public messageTypeModule(IDy_Message_Service dy_Message_Service) : base("/v1/message")
        {
            this._dy_Message_Service = dy_Message_Service;
            //留言
            Post["/send", true] = async (param, token) =>
            {
                Result res = new Result();
                var dto = this.Bind<dy_message>();
                if (dto == null || string.IsNullOrWhiteSpace(dto.user) || string.IsNullOrWhiteSpace(dto.mobile))
                {
                    res.code = ResultType.fail;
                    res.message = "参数错误";
                    return Response.AsJson(res);
                }
                res.data = await _dy_Message_Service.userComment(dto);
                return Response.AsJson(res);
            };
        }
    }
}